package com.gxp.web.controller;

import com.gxp.common.core.controller.BaseController;
import com.gxp.common.core.page.TableDataInfo;
import com.gxp.system.domain.ZkInstrument;
import com.gxp.system.domain.dto.ZkAutoExpinfoDto;
import com.gxp.system.service.IZkAutoExpinfoService;
import com.gxp.system.service.IZkInstrumentService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 仪器信息显示（我的仪器）
 */
@Controller
@RequestMapping("/system/inst")
public class InstrumentController extends BaseController {

    @Autowired
    private IZkInstrumentService instrumentService;
    @Autowired
    private IZkAutoExpinfoService expinfoService;

    private String prefix = "system/instrument";

    /**
     * 主界面
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping()
    public String instrument(@Param("id") Long id,
                             @RequestParam(value = "isHighlight",required = false ,defaultValue = "false" ) boolean isHighlight,
                             @Param("expCode")String expCode,
                             ModelMap mmap){
        ZkInstrument instrument = instrumentService.selectZkInstrumentByInstId(id);
        mmap.put("instrument", instrument);
        //高亮显示
        if(isHighlight){
            mmap.put("isHighlight", isHighlight);
            mmap.put("expCode", expCode);
        }else {
            mmap.put("isHighlight", false);
            mmap.put("expCode", "1");
        }
        //是否全部展开
        return prefix + "/inst";
    }

    /**
     * 根据Id获取自动化实验数据
     * @param instId
     * @return
     */
    @PostMapping("/autoExp")
    @ResponseBody
    public TableDataInfo autoExp(@Param("instId")Long instId){
        List<ZkAutoExpinfoDto> expinfos = expinfoService.selectZkAutoExpinfoByInstId(instId);
        return getDataTable(expinfos);
    }
}
